java check how many digits in a number

109

how to get length of integer in java -

int length = (int) (Math.log10(number) + 1);

java check how many digits in a number -

int n = 1000;
int length = (int)(Math.log10(n)+1);

//NB: only valid for n > 0

Comments

Submit
0 Comments